package model

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

var db *gorm.DB

func init() {
	mysql := mysql.Open(fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local", "root",
		"root",
		"localhost:3306",
		"daxue"))
	var err error
	db, err = gorm.Open(mysql, &gorm.Config{
		Logger: logger.Default.LogMode(logger.Silent),
	})

	if err != nil {
		panic("连接数据库失败：" + err.Error())
	}
}

func DB() *gorm.DB {
	return db
}
